<?php

namespace App\Library;

class RateLimiter
{
    public static function limitBy(string $key, int $maxAttempts, int $decayMinutes)
    {
        $rateLimiter = app(\Illuminate\Cache\RateLimiter::class);

        $key = sha1("rate_limit:$key");
        if ($rateLimiter->tooManyAttempts($key, $maxAttempts, $decayMinutes)) {
            return false;
        }
        $rateLimiter->hit($key, $decayMinutes);

        return true;
    }
}
